<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../js/vue.js"></script>

</head>
<body>

<div id="root">
    姓：<input type="text" v-model="firstName"></input>

    名：<input type="text" v-model="lastName"></input>

    全名：<span>{{fullName}}</span>
</div>


<script>
    new Vue({
        el: '#root',
        data: {
            firstName: '张',
            lastName: '三',
            fullName: '张三'
        },
        watch: {
            firstName(val) {
                this.fullName = val + '-' + this.lastName
            },

            lastName(val) {
                this.fullName = this.firstName + '-' + val
            }
        }
    })
</script>
</body>
</html>